import request from '@/utils/request'
import type {
  SpuData,
  HasSpuResponseData,
  AllTradeMark,
  SpuHasImg,
  SaleAttrResponseData,
  HasSaleAttrResponseData,
  SkuData,
  SkuInfoData,
} from './type'

//获取spu品牌属性
// export const reqSpuAttrListAPT = (page: any, limit: any) =>
//   request<any, any>({
//     url: `/admin/product/attrInfoList/${page}/${limit}`,
//     method: 'get',
//   })
//获取已有spu数据
export const reqHasSpuAPI = (
  page: number,
  limit: number,
  category3Id: number | string
) =>
  request.get<any, HasSpuResponseData>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  )

//获取全部品牌数据接口
export const reqAllTrademarkAPI = () =>
  request.get<any, AllTradeMark>(
    `/admin/product/baseTrademark/getTrademarkList`
  )
//获取某一个spu下的照片数据
export const reqSpuImageListAPI = (spuId: number | string) =>
  request.get<any, SpuHasImg>(`/admin/product/spuImageList/${spuId}`)
//获取一个spu有多少个销售属性接口
export const reqSpuSaleAttrListAPI = (spuId: number | string) =>
  request.get<any, SaleAttrResponseData>(
    `/admin/product/spuSaleAttrList/${spuId}`
  )
//获取整个项目全部销售属性接口
export const reqAllSaleAttrAPI = () =>
  request.get<any, HasSaleAttrResponseData>(`/admin/product/baseSaleAttrList`)

//添加或者更新spu接口
export const reqAddOrUpdataSpuAPI = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(`/admin/product/updateSpuInfo`, data)
  } else {
    return request.post<any, any>(`/admin/product/saveSpuInfo`, data)
  }
}

//给一个品牌添加sku产品的接口
export const reqAddSkuAPI = (data: any) =>
  request.post<any, SkuData>(`/admin/product/saveSkuInfo`, data)

//获取某一个spu下的所有sku接口
export const reqSkuListAPI = (spuId: number | string) =>
  request.get<any, SkuInfoData>(`/admin/product/findBySpuId/${spuId}`)
//删除一个spu接口
export const reqDeleteSpuAPI = (spuId: number | string) =>
  request.delete<any, any>(`/admin/product/deleteSpu/${spuId}`)
